import { ref, onBeforeMount } from 'vue'
import categoryApi from '@/api/categoryApi';

export function useGoodTypeTree() {
	const goodTypeTree = ref([])
	
	const HGetTree = () => {
		categoryApi
			.getGoodTypeTree()
			.then((res) => {
				goodTypeTree.value = res.data.map((item) => ({
					id: item.id,
					icon: item.iconPath,
					name: item.goodsCategoryName,
					path: ''
				}));
			})
			.catch((err) => {
				console.error(err); // 处理错误情况，例如显示错误提示信息。
			});
	};
	
	onBeforeMount(() => {
		HGetTree();
	})

	return { goodTypeTree }
}